package com.base.cn.platform.os.controller.mobile.classes.index;

import com.base.cn.platform.os.common.MobileBaseController;
import com.base.cn.platform.os.common.utils.count.PageFrom;
import com.base.cn.platform.os.common.utils.count.PageKeyUtils;
import com.base.cn.platform.os.service.course.classes.ClassesService;
import com.base.cn.platform.os.service.manage.count.PageViewCountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * H5班级首页Controller
 *
 * @author zsw
 * @create 2018/7/5
 */
@Controller
@RequestMapping("/mobile/class")
public class MobileClassIndexController extends MobileBaseController {

    @Autowired
    private ClassesService classesService;
    @Autowired
    private PageViewCountService pageViewCountService;

    /**
     * 班级首页
     */
    @RequestMapping("/index")
    public String toClassIndex() {
        pageViewCountService.addPageCount(PageKeyUtils.CLASS_INDEX, PageFrom.PAGE_FROM_MOBILE);
        return resultPage("/class/index/class-index");
    }

    /**
     * 加载班级
     *
     * @param currentPage
     * @param clazz 班级搜索条件
     */
    @RequestMapping("/ajax/list/class")
    public String listClasses(HttpServletRequest request,
                              Model model,
                              @RequestParam(value = "currentPage",required = false,defaultValue = "0") int currentPage,
                              @RequestBody Map<String,Object> clazz) {
        clazz.put("status",1);
        Map<String, Object> classesListPage = classesService.findClassesListPage(clazz, currentPage, 10, false, false, false, false, 1);
        model.addAttribute("dataMap",classesListPage);
        return resultPage("/class/index/ajax-list-class");
    }

}
